﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using System.Data;
using IFRS_Global;
using System.Threading;
using System.Globalization;


public partial class IFRS_WIN09_3V : PageBase
{
    #region "---------- Events -----------"
    protected void Page_Load(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            this.ViewMenu();
            this.AddClientScript();
            this.BindDDL();
            if (Request.QueryString["id"] != null)
            {
                this.BindData(Convert.ToInt32(Request.QueryString["id"].ToString()));
            }
        }
        else
        {
            ClientScript.RegisterHiddenField("isPostBack", "1");
        }
    }

    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN09_1S.aspx");
    }

    #endregion
    #region "----- Methods -------"
    private void ViewMenu()
    {
        this.MenuTitleBar = Resources.ifrsMenu.WIN09_3V;
    }
    private void AddClientScript()
    {
        btnCANCEL.Attributes["OnClick"] = "if(!confirm(\"" + Resources.ifrsResource.ConfirmCancel + "\")) return false;";
     
    }
  
    private void BindDDL()
    {
        ddlCustomerPayFreqTimeBase.SetData(DDL_TYPE.PaymentFrequencyTimeBase, "", true, false);
        ddlInterestAdjFreqTimeBase.SetData(DDL_TYPE.PaymentFrequencyTimeBase, "", true, false);
        ddlInterestPayFreqTimeBase.SetData(DDL_TYPE.PaymentFrequencyTimeBase, "", true, false);
        ddlPaymentFreqTimeBase.SetData(DDL_TYPE.PaymentFrequencyTimeBase, "", true, false);
        ddlContractLoanTypeID.SetData(DDL_TYPE.ContractLoanType, "", true, false);
        ddlCreditLevelID.SetData(DDL_TYPE.CreditLevel, "", true, false);
        ddlDayCountMethod.SetData(DDL_TYPE.DayCountMethod, "", true, false);
        ddlInterestTypeID.SetData(DDL_TYPE.InterestType, "", true, false);
        ddlPaymentDate.SetData(DDL_TYPE.PaymentDate, "", true, false);
        ddlPaymentCondition.SetData(DDL_TYPE.PaymentCondition, "", true, false);
    }
    private void BindData(int ID)
    {
        var vSPM = new SPR_SORPORMORCREDIT();
        DataTable dtvSPM = vSPM.SEARCH_BYID(ID);
        List<SorPorMorCredit> SPM = new List<SorPorMorCredit>();
        ConvertHelper.ConvertDataTableToObject(dtvSPM, SPM);

        if (dtvSPM.Rows.Count > 0)
        {
            //TextBox
           
            txtAccountNo.Text = SPM[0].AccountNo;
            txtTransactionDate.Text = SPM[0].TransactionDate.DateToString();
            txtAdditionalInterest.Text = SPM[0].AdditionalInterest.ToString();
            txtCapitalAmount.Text = SPM[0].CapitalAmount.ToString();
            txtCollateralValue.Text = SPM[0].CollateralValue.ToString();
            txtContractEndDate.Text = SPM[0].ContractEndDate.DateToString();
            txtContractStartDate.Text = SPM[0].ContractStartDate.DateToString();
            txtCostCenter.Text = SPM[0].COST_CENTER_NM;
            txtCurrencyCodeCD.Text = SPM[0].CurrencyCode;
            txtCustomer_ID.Text = SPM[0].CustomerCode;
            txtCustomerPayFreq.Text = SPM[0].CustomerPayFreq.ToString();
            txtEndCalInterestDate.Text = SPM[0].EndCalInterestDate.DateToString();
            txtFirstPaymentDate.Text = SPM[0].FirstPaymentDate.DateToString();
            txtGLAccountCode.Text = SPM[0].GLAccountName;
            txtInterestAdjFreq.Text = SPM[0].InterestAdjFreq.ToString();
            txtInterestPayFreq.Text = SPM[0].InterestPayFreq.ToString();
            txtInterestRate.Text = SPM[0].InterestRate.ToString();
            txtLastPaymentDate.Text = SPM[0].LastPaymentDate.DateToString();
            txtLoanObjectiveID.Text = SPM[0].CBT_DESC_LEV1;
            txtMisPaymentDate.Text = SPM[0].MisPaymentDate.DateToString();
            txtNextPaymentDate.Text = SPM[0].NextPaymentDate.DateToString();
            txtNoOfPayment.Text = SPM[0].NoOfPayment.ToString();
            txtPaymentFreq.Text = SPM[0].PaymentFreq.ToString();
            txtReferenceInterestCD.Text = SPM[0].ReferenceInterestNM;
            txtReservedAmount.Text = SPM[0].ReservedAmount.ToString();
            txtStartInterestRate.Text = SPM[0].StartInterestRate.ToString();
            txtStartPaymentDate.Text = SPM[0].StartPaymentDate.DateToString();
            txtTermAmount.Text = SPM[0].TermAmount.ToString();
            txtUnpaidAmount.Text = SPM[0].UnpaidAmount.ToString();
            txtUnpaidInterest.Text = SPM[0].UnpaidInterest.ToString();
            //DDL
            ddlContractLoanTypeID.SelectedValue = SPM[0].ContractLoanTypeID.ToString();
            ddlCreditLevelID.SelectedValue = SPM[0].CreditLevelID.ToString();
            ddlCustomerPayFreqTimeBase.SelectedValue = SPM[0].CustomerPayFreqTimeBase;
            ddlDayCountMethod.SelectedValue = SPM[0].DayCountMethodID.ToString();
            ddlInterestAdjFreqTimeBase.SelectedValue = SPM[0].InterestAdjFreqTimeBase;
            ddlInterestPayFreqTimeBase.SelectedValue = SPM[0].InterestPayFreqTimeBase;
            ddlInterestTypeID.SelectedValue = SPM[0].InterestTypeID.ToString();
            ddlPaymentCondition.SelectedValue = SPM[0].PaymentConditionID.ToString();
            ddlPaymentDate.SelectedValue = SPM[0].PaymentDateID.ToString();
            ddlPaymentFreqTimeBase.SelectedValue = SPM[0].PaymentFreqTimeBase;
          

            if (SPM[0].DebtAdjustFlag)
            {
                cbDebtAdjust.Checked = true;
            }
            else
            {
                cbDebtAdjust.Checked = false;
            }

        }
    }
    
 
    #endregion
}